package com.guangsi.compute;

import java.util.concurrent.CountDownLatch;

public class ComputeProcess extends Thread {
    private volatile boolean exit = false;
    long ilde = 0L;
    private CountDownLatch latch;

    public synchronized void exit() {
        this.exit = true;
    }

    public ComputeProcess(double hope, CountDownLatch latch) {
        double alreadyUsed = CpuUtils.getInstance().getCpuUsage();
        if (alreadyUsed < 0.0D) {
            alreadyUsed = 0.3D;
        }
        this.ilde = (long) ((10.0D + 10.0D * alreadyUsed - hope * 10) / (hope - alreadyUsed));
        this.latch = latch;
    }

    @Override
    public void run() {
        try {
            double m = 178.21D;
            label67:
            while (!this.exit) {
                long nowSys = System.currentTimeMillis();
                do {
                    if (System.currentTimeMillis() - nowSys > 10L) {
                        if (!this.exit) {
                            sleep(this.ilde);
                        }
                        continue label67;
                    }
                    m = m * 3.1415D / 3.1415D;
                } while (!this.exit);

                throw new InterruptedException();
            }
        } catch (InterruptedException var8) {
            ;
        } finally {
            this.latch.countDown();
        }
    }
}
